feat(clone): add structuredClone support for Error objects and relate…#5280
feat(clone): add structuredClone support for Error objects and relate…#5280akshatnathani wants to merge 2 commits intoboa-dev:mainfrom
Conversation
core/runtime/src/store/from.rs
Outdated
|
|
||
| let name = to_optional_string("name", context)?; | ||
| let stack = to_optional_string("stack", context)?; | ||
| let cause = to_optional_string("cause", context)?; |
There was a problem hiding this comment.
cause is getting flattened into a string here before it goes into the store. that works for simple text causes, but it breaks real cases like new Error("boom", { cause: { code: 7 } }), where the cloned error should still keep the original object as its cause.
There was a problem hiding this comment.
Great catch. I fixed the cause handling so that it is preserved as structured data rather than stringified. Added regression coverage for both structuredClone and postMessage paths, and also looking into the AggregateError issue you pointed out, and will follow up with the patch/tests shortly.
| let (kind, name, message, stack, cause) = error_data; | ||
| let message = message.to_js_string().to_std_string_escaped(); | ||
| let native = match kind { | ||
| ErrorKind::Aggregate => JsNativeError::aggregate(Vec::new()), |
There was a problem hiding this comment.
this rebuilds AggregateError with an empty list, so the cloned value loses its errors property on the way back out. i checked this with a quick repro and structuredClone(new AggregateError([new Error("inner")], "agg")) comes back with errors.length === 0.
0f3a392 to
98a2ce6
Compare
This Pull Request fixes/closes #5279.
It changes the following: